#include <iostream>
#include <array>
#include <vector>
#include <boost/asio.hpp>

using namespace std;
using boost::asio::ip::tcp;

int main(int argc, char const *argv[])
{
    try
    {
        if (argc != 2)
        {
            cerr << "Usage: client <host>" << endl;
            return 1;
        }
        boost::asio::io_service io_service;

        tcp::resolver           resolver(io_service);
        tcp::resolver::query    query(argv[1], "12345");
        tcp::resolver::iterator itr = resolver.resolve(query);

        tcp::socket socket(io_service);
        boost::asio::connect(socket, itr);

        for (;;)
        {
            array<char, 128>          buf;
            vector<int>               buf1;
            boost::system::error_code error;

            size_t len = socket.read_some(boost::asio::buffer(buf), error);

            if (error == boost::asio::error::eof)
                break;
            else if (error)
                throw boost::system::system_error(error);

            cout.write(buf.data(), len);
        }
    }
    catch (std::exception &e)
    {
        cerr << e.what() << endl;
    }
    return 0;
}
